package edu.byu.intex2.tester;

import junit.framework.*;
import java.util.*;
import java.text.SimpleDateFormat;
import edu.byu.intex2.data.*;
import edu.byu.intex2.data.bo.*;
import edu.byu.intex2.data.dao.*;

/** The container of all the tests */
public class TestDataLayerTests extends TestCase {

    /** Constructor */
    public TestDataLayerTests() {
    }//constructor

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testPerson() throws Exception {
        String guid = GUID.generate();
        Person person = PersonDAO.getInstance().create(guid);
        person.setFirstName("Mike");
        person.setLastName("Chambers");
        person.setAddress("Cheyenne Mountain, CO");
        person.setPhone("801-422-BYU1");
        person.save(); // will save with insert statement

        person.setAddress("Glacier National Park, MO");
        person.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Person person2 = PersonDAO.getInstance().read(guid);
        assertSame(person, person2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Person person3 = PersonDAO.getInstance().read(guid);
        assertNotSame(person, person3);
        assertEquals(person.getFullName(), person3.getFullName());
        assertNotNull(person.getFullName());
        assertEquals(person.getId(), person3.getId());
        assertNotNull(person.getId());
        assertEquals(person.getAddress(), person3.getAddress());
        assertNotNull(person.getAddress());
        assertEquals(person.getPhone(), person3.getPhone());
        assertNotNull(person.getPhone());

    }//testPerson

    /** Tests the customer BO and DAO -- currently does not work */
    public void testCustomer() throws Exception {
        String guid = GUID.generate();
        Customer customer = CustomerDAO.getInstance().create(guid);

        // Set Person Attributes
        customer.setFirstName("Bob");
        customer.setLastName("Dillan");
        customer.setAddress("Portland, OR");
        customer.setPhone("801-567-BYU3");

        // Set Employee Attributes
        customer.setHighPrice(35000);
        customer.setLowPrice(10000);

        customer.save(); // will save with insert statement

        customer.setHighPrice(25000);
        customer.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Customer customer2 = CustomerDAO.getInstance().read(guid);
        assertSame(customer, customer2);

        // this one will come all the way from the DB -- should be a new object

        Cache.getInstance().clear();
        Customer customer3 = CustomerDAO.getInstance().read(guid);

        // Customer Asserts
        assertEquals(customer.getHighPrice(), customer3.getHighPrice());
        assertNotNull(customer.getHighPrice());
        assertEquals(customer.getLowPrice(), customer3.getLowPrice());
        assertNotNull(customer.getLowPrice());

        // Person Asserts
        assertNotSame(customer, customer3);
        assertEquals(customer.getFullName(), customer3.getFullName());
        assertNotNull(customer.getFullName());
        assertEquals(customer.getId(), customer3.getId());
        assertNotNull(customer.getId());
        assertEquals(customer.getAddress(), customer3.getAddress());
        assertNotNull(customer.getAddress());
        assertEquals(customer.getPhone(), customer3.getPhone());
        assertNotNull(customer.getPhone());

        // test the search method in the DAO
        /*
        List<CustomerSearch> allCust;
        allCust = CustomerDAO.getInstance().getAll();
        assertNotNull(allCust);*/

    }//testPerson

    /** Tests the emplyee BO and DAO */
    public void testEmployee() throws Exception {
        String guid = GUID.generate();
        Employee employee = EmployeeDAO.getInstance().create(guid);

        // Set Person Attributes
        employee.setFirstName("Mr");
        employee.setLastName("Employee");
        employee.setAddress("Portland, OR");
        employee.setPhone("801-567-BYU3");

        // Set Employee Attributes
        employee.setUsername("mremployee");
        employee.setPassword("mypassword1");
        employee.setPosition("salesperson");

        employee.save(); // will save with insert statement

        employee.setPassword("Password1");
        employee.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Employee employee2 = EmployeeDAO.getInstance().read(guid);
        assertSame(employee, employee2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Employee employee3 = EmployeeDAO.getInstance().read(guid);

        // Customer Asserts
        assertNotSame(employee, employee3);
        assertEquals(employee.getUsername(), employee3.getUsername());
        assertNotNull(employee.getUsername());
        assertEquals(employee.getPassword(), employee3.getPassword());
        assertNotNull(employee.getPassword());
        assertEquals(employee.getPosition(), employee3.getPosition());
        assertNotNull(employee.getPosition());

        // Person Asserts
        assertEquals(employee.getFullName(), employee3.getFullName());
        assertNotNull(employee.getFullName());
        assertEquals(employee.getId(), employee3.getId());
        assertNotNull(employee.getId());
        assertEquals(employee.getAddress(), employee3.getAddress());
        assertNotNull(employee.getAddress());
        assertEquals(employee.getPhone(), employee3.getPhone());
        assertNotNull(employee.getPhone());
    }//testPerson

    /** Tests the emplyee BO and DAO */
    public void testSalesperson() throws Exception {
        String guid = GUID.generate();
        Salesperson salesperson = SalespersonDAO.getInstance().create(guid);

        // Set Person Attributes
        salesperson.setFirstName("Jim");
        salesperson.setLastName("Halpert");
        salesperson.setAddress("Pittsburg, PI");
        salesperson.setPhone("801-567-8394");

        // Set Employee Attributes
        salesperson.setUsername("happysalesperson");
        salesperson.setPassword("Password1");
        salesperson.setPosition("salesperson");

        // Set Salesperson Attributes
        salesperson.setCommissionPercent(.05);

        salesperson.save(); // will save with insert statement

        salesperson.setCommissionPercent(.03);
        salesperson.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Salesperson salesperson2 = SalespersonDAO.getInstance().read(guid);
        assertSame(salesperson, salesperson2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Salesperson salesperson3 = SalespersonDAO.getInstance().read(guid);

        // Salesperson Asserts
        assertNotSame(salesperson, salesperson3);
        assertEquals(salesperson.getCommissionPercent(), salesperson3.getCommissionPercent());
        assertNotNull(salesperson.getCommissionPercent());

        // Employee Asserts
        assertEquals(salesperson.getUsername(), salesperson3.getUsername());
        assertNotNull(salesperson.getUsername());
        assertEquals(salesperson.getPassword(), salesperson3.getPassword());
        assertNotNull(salesperson.getPassword());
        assertEquals(salesperson.getPosition(), salesperson3.getPosition());
        assertNotNull(salesperson.getPosition());

        // Person Asserts
        assertEquals(salesperson.getFullName(), salesperson3.getFullName());
        assertNotNull(salesperson.getFullName());
        assertEquals(salesperson.getId(), salesperson3.getId());
        assertNotNull(salesperson.getId());
        assertEquals(salesperson.getAddress(), salesperson3.getAddress());
        assertNotNull(salesperson.getAddress());
        assertEquals(salesperson.getPhone(), salesperson3.getPhone());
        assertNotNull(salesperson.getPhone());

    }//testPerson

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testPhysicalCar() throws Exception {
        String guid = GUID.generate();
        PhysicalCar physicalCar = PhysicalCarDAO.getInstance().create(guid);

        // Set Physical Car Attributes
        physicalCar.setVin("1234567890123456P");
        physicalCar.setPrice(18500);
        physicalCar.setColor("Blue");
        physicalCar.save(); // will save with insert statement

        physicalCar.setColor("Red");
        physicalCar.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        PhysicalCar physicalCar2 = PhysicalCarDAO.getInstance().read(guid);
        assertSame(physicalCar, physicalCar2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        PhysicalCar physicalCar3 = PhysicalCarDAO.getInstance().read(guid);
        assertNotSame(physicalCar, physicalCar3);
        assertEquals(physicalCar.getVin(), physicalCar3.getVin());
        assertNotNull(physicalCar.getVin());
        assertEquals(physicalCar.getPrice(), physicalCar3.getPrice());
        assertNotNull(physicalCar.getPrice());
        assertEquals(physicalCar.getColor(), physicalCar3.getColor());
        assertNotNull(physicalCar.getColor());

        // Test getByVIN
        PhysicalCar physicalCar4 = PhysicalCarDAO.getInstance().getByVIN("1234567890123456P");
        assertSame(physicalCar3, physicalCar4);
        assertEquals(physicalCar3.getVin(), physicalCar4.getVin());
    }//testPhysicalCar

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testUsedCar() throws Exception {
        String guid = GUID.generate();
        UsedCar usedCar = UsedCarDAO.getInstance().create(guid);

        // Set Used Car Attributes
        usedCar.setCarCondition("Good");
        usedCar.setMileage(65000);

        // Set Physical Car Attributes
        usedCar.setVin("USEDCARVIN1292393");
        usedCar.setPrice(18500);
        usedCar.setColor("Blue");
        usedCar.save(); // will save with insert statement

        usedCar.setCarCondition("Average");
        usedCar.setMileage(60000);
        usedCar.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        UsedCar usedCar2 = UsedCarDAO.getInstance().read(guid);
        assertSame(usedCar, usedCar2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        UsedCar usedCar3 = UsedCarDAO.getInstance().read(guid);

        // Assert Used Car Attributes
        assertNotSame(usedCar, usedCar3);
        assertEquals(usedCar.getCarCondition(), usedCar3.getCarCondition());
        assertNotNull(usedCar.getCarCondition());
        assertEquals(usedCar.getMileage(), usedCar3.getMileage());
        assertNotNull(usedCar.getMileage());

        // Assert Physical Car Attributes
        assertEquals(usedCar.getVin(), usedCar3.getVin());
        assertNotNull(usedCar.getVin());
        assertEquals(usedCar.getPrice(), usedCar3.getPrice());
        assertNotNull(usedCar.getPrice());
        assertEquals(usedCar.getColor(), usedCar3.getColor());
        assertNotNull(usedCar.getColor());
    }//testUsedCar

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testNewCar() throws Exception {
        String guid = GUID.generate();
        NewCar newCar = NewCarDAO.getInstance().create(guid);

        // Set New Car Attributes
        newCar.setMSRP(45000);

        // Set Physical Car Attributes
        newCar.setVin("NEWCARVIN129302");
        newCar.setPrice(18500);
        newCar.setColor("Blue");
        newCar.save(); // will save with insert statement

        newCar.setMSRP(35000);
        newCar.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        NewCar newCar2 = NewCarDAO.getInstance().read(guid);
        assertSame(newCar, newCar2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        NewCar newCar3 = NewCarDAO.getInstance().read(guid);

        // Assert Used Car Attributes
        assertNotSame(newCar, newCar3);
        assertEquals(newCar.getMSRP(), newCar3.getMSRP());
        assertNotNull(newCar.getMSRP());

        // Assert Physical Car Attributes
        assertEquals(newCar.getVin(), newCar3.getVin());
        assertNotNull(newCar.getVin());
        assertEquals(newCar.getPrice(), newCar3.getPrice());
        assertNotNull(newCar.getPrice());
        assertEquals(newCar.getColor(), newCar3.getColor());
        assertNotNull(newCar.getColor());
    }//testNewCar

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testWarranty() throws Exception {
        String guid = GUID.generate();
        Warranty warranty = WarrantyDAO.getInstance().create(guid);
        warranty.setMiles(50000);
        warranty.setMonths(18);
        warranty.setWarrantyType("Limited");
        warranty.save(); // will save with insert statement

        warranty.setWarrantyType("Extended");
        warranty.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Warranty warranty2 = WarrantyDAO.getInstance().read(guid);
        assertSame(warranty, warranty2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Warranty warranty3 = WarrantyDAO.getInstance().read(guid);
        assertNotSame(warranty, warranty3);
        assertEquals(warranty.getMiles(), warranty3.getMiles());
        assertNotNull(warranty.getMiles());
        assertEquals(warranty.getMonths(), warranty3.getMonths());
        assertNotNull(warranty.getMonths());
        assertEquals(warranty.getWarrantyType(), warranty3.getWarrantyType());
        assertNotNull(warranty.getWarrantyType());
    }//testWarranty

    /** Tests the sale BO and DAO (this really should be split into many methods) */
    public void testSale() throws Exception {
        String guid = GUID.generate();
        Sale sale = SaleDAO.getInstance().create(guid);

        // Create a salesperson
        Salesperson salesperson = SalespersonDAO.getInstance().create(GUID.generate());
        SalespersonDAO.getInstance().save(salesperson);

        // Set Sale Attributes
        sale.setTotalPrice(31345);
        sale.setTax(2109.23);
        sale.setFinanced("1");
        sale.setDownPayment(20000);
        sale.setPaymentPlan("Monthly");
        sale.setDiscount(2500);
        sale.setDate(new java.util.Date(2009, 2, 13));
        sale.setSalesPersonBonus(2000);
        sale.setSalesPersonId(salesperson.getId());
        sale.save(); // will save with insert statement

        sale.setPaymentPlan("Yearly");
        sale.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Sale sale2 = SaleDAO.getInstance().read(guid);
        assertSame(sale, sale2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Sale sale3 = SaleDAO.getInstance().read(guid);
        assertNotSame(sale, sale3);
        assertEquals(sale.getTotalPrice(), sale3.getTotalPrice());
        assertNotNull(sale.getTotalPrice());
        assertEquals(sale.getTax(), sale3.getTax());
        assertNotNull(sale.getTax());
        assertEquals(sale.getFinanced(), sale3.getFinanced());
        assertNotNull(sale.getFinanced());
        assertEquals(sale.getDownPayment(), sale3.getDownPayment());
        assertNotNull(sale.getDownPayment());
        assertEquals(sale.getPaymentPlan(), sale3.getPaymentPlan());
        assertNotNull(sale.getPaymentPlan());
        assertEquals(sale.getDiscount(), sale3.getDiscount());
        assertNotNull(sale.getDiscount());
        assertEquals(sale.getDate(), sale3.getDate());
        assertNotNull(sale.getDate());
        assertEquals(sale.getSalespersonBonus(), sale3.getSalespersonBonus());
        assertNotNull(sale.getSalespersonBonus());
        assertEquals(sale.getSalesPersonId(), sale3.getSalesPersonId());
        assertNotNull(sale.getSalesPersonId());
    }//testSale

    /** Tests the saleLine BO and DAO */
    public void testSaleLine() throws Exception {
        // Create the Sale First.
        String guid = GUID.generate();
        Sale sale = SaleDAO.getInstance().create(guid);

        // Create a salesperson
        Salesperson salesperson = SalespersonDAO.getInstance().create(GUID.generate());
        SalespersonDAO.getInstance().save(salesperson);

        // Set Sale Attributes
        sale.setTotalPrice(31345);
        sale.setTax(2109.23);
        sale.setFinanced("1");
        sale.setDownPayment(20000);
        sale.setPaymentPlan("Monthly");
        sale.setDiscount(2500);
        sale.setDate(new java.util.Date(2009, 2, 13));
        sale.setSalesPersonBonus(2000);
        sale.setSalesPersonId(salesperson.getId());
        sale.save(); // will save with insert statement

        // Create the Physical Car
        PhysicalCar physicalCar = PhysicalCarDAO.getInstance().create(GUID.generate());

        // Set Physical Car Attributes
        physicalCar.setVin("SL1PCVIN500549");
        physicalCar.setPrice(18500);
        physicalCar.setColor("Hot Pink");
        physicalCar.save(); // will save with insert statement

        // Create the Sale Line
        SaleLine saleLine = SaleLineDAO.getInstance().create(sale.getId(), physicalCar.getVin());
        saleLine.setListPrice(35000);
        saleLine.setActualPrice(32000);
        saleLine.save();
    }

    /** Tests the saleLine BO and DAO */
    public void testTradeInLine() throws Exception {
        // Create the Sale First.
        String guid = GUID.generate();
        Sale sale = SaleDAO.getInstance().create(guid);

        // Create a salesperson
        Salesperson salesperson = SalespersonDAO.getInstance().create(GUID.generate());
        SalespersonDAO.getInstance().save(salesperson);

        // Set Sale Attributes
        sale.setTotalPrice(31345);
        sale.setTax(2109.23);
        sale.setFinanced("1");
        sale.setDownPayment(20000);
        sale.setPaymentPlan("Monthly");
        sale.setDiscount(2500);
        sale.setDate(new java.util.Date(2009, 2, 13));
        sale.setSalesPersonBonus(2000);
        sale.setSalesPersonId(salesperson.getId());
        sale.save(); // will save with insert statement

        // Create the Used Car
        UsedCar usedCar = UsedCarDAO.getInstance().create(GUID.generate());

        // Set Physical Car Attributes
        usedCar.setVin("TLUSEDCARVIN10");
        usedCar.setPrice(20500);
        usedCar.setColor("Magenta");

        // Set Used Car Attributes
        usedCar.setCarCondition("Excellent");
        usedCar.setMileage(75000);
        usedCar.save(); // will save with insert statement

        // Create the Trade In Line
        TradeInLine tradeInLine = TradeInLineDAO.getInstance().create(sale.getId(), usedCar.getVin());
        tradeInLine.setTradeInValue(8250);
        tradeInLine.setMileage(75000);
        tradeInLine.save();

        // Update the Trade In Line
        tradeInLine.setTradeInValue(9000);
        tradeInLine.save(); // this will save with the update statement

        // Assert we don't have null values
        assertNotNull(tradeInLine.getTradeInValue());
        assertNotNull(tradeInLine.getMileage());
    }

    /** Tests the saleLine BO and DAO */
    public void testSaleWithBothLines() throws Exception {
        // Create the Sale First.
        String guid = GUID.generate();
        Sale sale = SaleDAO.getInstance().create(guid);

        // Create a salesperson
        Salesperson salesperson = SalespersonDAO.getInstance().create(GUID.generate());
        SalespersonDAO.getInstance().save(salesperson);

        // Set Sale Attributes
        sale.setTotalPrice(31345);
        sale.setTax(2109.23);
        sale.setFinanced("1");
        sale.setDownPayment(20000);
        sale.setPaymentPlan("Monthly");
        sale.setDiscount(2500);
        sale.setDate(new java.util.Date(2009, 2, 13));
        sale.setSalesPersonBonus(2000);
        sale.setSalesPersonId(salesperson.getId());

        // Create the Physical Car
        PhysicalCar physicalCar = PhysicalCarDAO.getInstance().create(GUID.generate());

        // Set Physical Car Attributes
        physicalCar.setVin("SBOTHLINE191");
        physicalCar.setPrice(18500);
        physicalCar.setColor("Hot Pink");
        physicalCar.save(); // will save with insert statement

        // Create the Sale Line
        SaleLine saleLine = SaleLineDAO.getInstance().create(sale.getId(), physicalCar.getVin());
        saleLine.setListPrice(35000);
        saleLine.setActualPrice(32000);

        // Add Sale Line to Sale
        sale.addSaleLine(saleLine);

        // Create the Used Car
        UsedCar usedCar = UsedCarDAO.getInstance().create(GUID.generate());

        // Set Physical Car Attributes
        usedCar.setVin("SBOTHLIIN3039");
        usedCar.setPrice(15600);
        usedCar.setColor("Blue");

        // Set Used Car Attributes
        usedCar.setCarCondition("Poor");
        usedCar.setMileage(125000);
        usedCar.save(); // will save with insert statement

        // Create the Trade In Line
        TradeInLine tradeInLine = TradeInLineDAO.getInstance().create(sale.getId(), usedCar.getVin());
        tradeInLine.setTradeInValue(2500);
        tradeInLine.setMileage(125000);

        // Add Trade In Line to Sale
        sale.addTradeInLine(tradeInLine);

        // Save the Sale (which will include all saleLines)
        sale.save(); // will save with insert statement
    }

    /** Tests the serviceFacility BO and DAO*/
    public void testServiceFacility() throws Exception {
        String guid = GUID.generate();
        ServiceFacility sf = ServiceFacilityDAO.getInstance().create(guid);
        sf.setAddress("123 Easy Street");
        sf.save(); // will save with insert statement

        sf.setAddress("254 Sesame Street");
        sf.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        ServiceFacility sf2 = ServiceFacilityDAO.getInstance().read(guid);
        assertSame(sf, sf2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        ServiceFacility sf3 = ServiceFacilityDAO.getInstance().read(guid);
        assertNotSame(sf, sf3);
        assertEquals(sf.getAddress(), sf3.getAddress());
        assertNotNull(sf.getAddress());
    }//testServiceFacility

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testDealership() throws Exception {
        // Create a Service Facility
        ServiceFacility sf = ServiceFacilityDAO.getInstance().create(GUID.generate());
        ServiceFacilityDAO.getInstance().save(sf);

        String guid = GUID.generate();
        Dealership dealership = DealershipDAO.getInstance().create(guid);
        dealership.setAddress("123 Easy Street");
        dealership.setPhone("8013610903");
        dealership.setServiceFacilityId(sf.getId());
        dealership.save(); // will save with insert statement

        dealership.setAddress("254 Sesame Street");
        dealership.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Dealership dealership2 = DealershipDAO.getInstance().read(guid);
        assertSame(dealership, dealership2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Dealership dealership3 = DealershipDAO.getInstance().read(guid);
        assertNotSame(dealership, dealership3);
        assertEquals(dealership.getAddress(), dealership3.getAddress());
        assertNotNull(dealership.getAddress());
        assertEquals(dealership.getPhone(), dealership3.getPhone());
        assertNotNull(dealership.getPhone());
        assertEquals(dealership.getServiceFacilityId(), dealership3.getServiceFacilityId());
        assertNotNull(dealership.getServiceFacilityId());
    }//testDealership

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testManufacturer() throws Exception {
        String guid = GUID.generate();
        Manufacturer manufacturer = ManufacturerDAO.getInstance().create(guid);
        manufacturer.setName("White Manufacturer");
        manufacturer.setEmail("satara@gmail.com");
        manufacturer.save(); // will save with insert statement

        manufacturer.setName("White Co. Manufacturer");
        manufacturer.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Manufacturer manufacturer2 = ManufacturerDAO.getInstance().read(guid);
        assertSame(manufacturer, manufacturer2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Manufacturer manufacturer3 = ManufacturerDAO.getInstance().read(guid);
        assertNotSame(manufacturer, manufacturer3);
        assertEquals(manufacturer.getName(), manufacturer3.getName());
        assertNotNull(manufacturer.getName());
        assertEquals(manufacturer.getEmail(), manufacturer3.getEmail());
        assertNotNull(manufacturer.getEmail());
    }//testManufacturer

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testPart() throws Exception {
        // Create a test Manufacturer for our part
        String guidm = GUID.generate();
        Manufacturer manufacturer = ManufacturerDAO.getInstance().create(guidm);
        manufacturer.setName("Brown Manufacturer");
        manufacturer.setEmail("satara@gmail.com");
        manufacturer.save(); // will save with insert statement

        // Create part
        String guid = GUID.generate();
        Part part = PartDAO.getInstance().create(guid);
        part.setPartNumber("d9d0c0d9");
        part.setPrice(15.00);
        part.setName("Air Filter");
        part.save(); // will save with insert statement

        part.setPrice(10.00);
        part.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Part part2 = PartDAO.getInstance().read(guid);
        assertSame(part, part2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Part part3 = PartDAO.getInstance().read(guid);
        assertNotSame(part, part3);
        assertEquals(part.getPartNumber(), part3.getPartNumber());
        assertNotNull(part.getPartNumber());
        assertEquals(part.getPrice(), part3.getPrice());
        assertNotNull(part.getPrice());
        assertEquals(part.getName(), part3.getName());
        assertNotNull(part.getName());
    }//testPart

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testTask() throws Exception {
        // Create task
        String guid = GUID.generate();
        Task task = TaskDAO.getInstance().create(guid);
        task.setDescription("Oil Change a roo");
        task.save(); // will save with insert statement

        task.setDescription("Oil Change");
        task.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Task task2 = TaskDAO.getInstance().read(guid);
        assertSame(task, task2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Task task3 = TaskDAO.getInstance().read(guid);
        assertNotSame(task, task3);
        assertEquals(task.getDescription(), task3.getDescription());
        assertNotNull(task.getDescription());
    }//testTask

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testConceptualCar() throws Exception {
        // Create conceptualCar
        String guid = GUID.generate();
        ConceptualCar conceptualCar = ConceptualCarDAO.getInstance().create(guid);
        conceptualCar.setMake("BMW");
        conceptualCar.setModel("M3");
        conceptualCar.setYear(2008);
        conceptualCar.setBasePrice(30000);
        conceptualCar.save(); // will save with insert statement

        conceptualCar.setYear(2009);
        conceptualCar.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        ConceptualCar conceptualCar2 = ConceptualCarDAO.getInstance().read(guid);
        assertSame(conceptualCar, conceptualCar2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        ConceptualCar conceptualCar3 = ConceptualCarDAO.getInstance().read(guid);
        assertNotSame(conceptualCar, conceptualCar3);
        assertEquals(conceptualCar.getMake(), conceptualCar3.getMake());
        assertNotNull(conceptualCar.getMake());
        assertEquals(conceptualCar.getModel(), conceptualCar3.getModel());
        assertNotNull(conceptualCar.getModel());
        assertEquals(conceptualCar.getYear(), conceptualCar3.getYear());
        assertNotNull(conceptualCar.getYear());
        assertEquals(conceptualCar.getBasePrice(), conceptualCar3.getBasePrice());
        assertNotNull(conceptualCar.getBasePrice());
    }//testConceptualCar

    /** Tests the person BO and DAO (this really should be split into many methods) */
    public void testTaskCC() throws Exception {
        // Create a task
        String guidt = GUID.generate();
        Task task = TaskDAO.getInstance().create(guidt);
        task.setDescription("Muffler Replacement");
        task.save(); // will save with insert statement

        // Create a conceptualCar
        String guidcc = GUID.generate();
        ConceptualCar cc = ConceptualCarDAO.getInstance().create(guidcc);
        cc.setMake("Honda");
        cc.setModel("Pilot");
        cc.setYear(2009);
        cc.setBasePrice(25000);
        cc.save(); // will save with insert statement

        // Create taskCC
        TaskCC taskCC = TaskCCDAO.getInstance().create(task.getId(), cc.getId());
        taskCC.setLaborTime(3);
        taskCC.save(); // will save with insert statement

        taskCC.setLaborTime(4);
        taskCC.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        TaskCC taskCC2 = TaskCCDAO.getInstance().read(task.getId(), cc.getId());
        assertSame(taskCC, taskCC2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        TaskCC taskCC3 = TaskCCDAO.getInstance().read(task.getId(), cc.getId());
        assertNotSame(taskCC, taskCC3);
        assertEquals(taskCC.getTaskId(), taskCC3.getTaskId());
        assertNotNull(taskCC.getTaskId());
        assertEquals(taskCC.getConceptualCarId(), taskCC3.getConceptualCarId());
        assertNotNull(taskCC.getConceptualCarId());
        assertEquals(taskCC.getLaborTime(), taskCC3.getLaborTime());
        assertNotNull(taskCC.getLaborTime());
    }//testTaskCC

    /** Tests the emplyee BO and DAO */
    public void testTechnician() throws Exception {
        // Create Service Facility
        String guidsf = GUID.generate();
        ServiceFacility sf = ServiceFacilityDAO.getInstance().create(guidsf);
        sf.setAddress("123 Blue Collar Way");
        sf.save(); // will save with insert statement

        String guid = GUID.generate();
        Technician technician = TechnicianDAO.getInstance().create(guid);

        // Set Person Attributes
        technician.setFirstName("Mark");
        technician.setLastName("BlueCollar");
        technician.setAddress("Chicago, IL");
        technician.setPhone("801-567-8194");

        // Set Employee Attributes
        technician.setUsername("happytechnician");
        technician.setPassword("Password1");
        technician.setPosition("technician");

        // Set Technician Attributes
        technician.setServiceFacilityId(guidsf);

        technician.save(); // will save with insert statement

        technician.setLastName("Blue Collar");
        technician.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Technician technician2 = TechnicianDAO.getInstance().read(guid);
        assertSame(technician, technician2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Technician technician3 = TechnicianDAO.getInstance().read(guid);

        // Technician Asserts
        assertNotSame(technician, technician3);
        assertEquals(technician.getServiceFacilityId(), technician3.getServiceFacilityId());
        assertNotNull(technician.getServiceFacilityId());

        // Employee Asserts
        assertEquals(technician.getUsername(), technician3.getUsername());
        assertNotNull(technician.getUsername());
        assertEquals(technician.getPassword(), technician3.getPassword());
        assertNotNull(technician.getPassword());
        assertEquals(technician.getPosition(), technician3.getPosition());
        assertNotNull(technician.getPosition());

        // Person Asserts
        assertEquals(technician.getFullName(), technician3.getFullName());
        assertNotNull(technician.getFullName());
        assertEquals(technician.getId(), technician3.getId());
        assertNotNull(technician.getId());
        assertEquals(technician.getAddress(), technician3.getAddress());
        assertNotNull(technician.getAddress());
        assertEquals(technician.getPhone(), technician3.getPhone());
        assertNotNull(technician.getPhone());

    }//testTechnician

    /** Tests the sale BO and DAO (this really should be split into many methods) */
    public void testService() throws Exception {
        // Create the Service
        String guid = GUID.generate();
        Service service = ServiceDAO.getInstance().create(guid);

        // Create a technician
        Technician technician = TechnicianDAO.getInstance().create(GUID.generate());
        TechnicianDAO.getInstance().save(technician);

        // Create a customer
        Customer customer = CustomerDAO.getInstance().create(GUID.generate());
        customer.setFirstName("Greg");
        customer.setLastName("Israelsen");
        customer.setAddress("276 East");
        customer.setPhone("8378485959");
        CustomerDAO.getInstance().save(customer);

        // Create a service facility
        ServiceFacility sf = ServiceFacilityDAO.getInstance().create(GUID.generate());
        ServiceFacilityDAO.getInstance().save(sf);

        // Create a physical car
        PhysicalCar pc = PhysicalCarDAO.getInstance().create(GUID.generate());
        PhysicalCarDAO.getInstance().save(pc);

        // Set Service Attributes
        service.setTotalPrice(1200);
        service.setTax(104.23);
        service.setServiceFacilityId(sf.getId());
        service.setTechnicianId(technician.getId());
        service.setCustomerId(customer.getId());
        service.setPhysicalCarId(pc.getId());
        service.setDate(new java.util.Date(2009, 3, 13));
        service.save(); // will save with insert statement

        service.setTotalPrice(1300);
        service.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Service service2 = ServiceDAO.getInstance().read(guid);
        assertSame(service, service2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Service service3 = ServiceDAO.getInstance().read(guid);
        assertNotSame(service, service3);
        assertEquals(service.getTotalPrice(), service3.getTotalPrice());
        assertNotNull(service.getTotalPrice());
        assertEquals(service.getTax(), service3.getTax());
        assertNotNull(service.getTax());
        assertEquals(service.getServiceFacilityId(), service3.getServiceFacilityId());
        assertNotNull(service.getServiceFacilityId());
        assertEquals(service.getTechnicianId(), service3.getTechnicianId());
        assertNotNull(service.getTechnicianId());
        assertEquals(service.getCustomerId(), service3.getCustomerId());
        assertNotNull(service.getCustomerId());
        assertEquals(service.getPhysicalCarId(), service3.getPhysicalCarId());
        assertNotNull(service.getPhysicalCarId());
        assertEquals(service.getDate(), service3.getDate());
        assertNotNull(service.getDate());
    }//testService

    /** Tests the saleLine BO and DAO */
    public void testServiceLine() throws Exception {
         // Create the Service
        String guids = GUID.generate();
        Service service = ServiceDAO.getInstance().create(guids);

        // Create a technician
        Technician technician = TechnicianDAO.getInstance().create(GUID.generate());
        TechnicianDAO.getInstance().save(technician);

        // Create a customer
        Customer customer = CustomerDAO.getInstance().create(GUID.generate());
        customer.setFirstName("Quinn");
        customer.setLastName("Garner");
        customer.setAddress("OA 303");
        customer.setPhone("8013432378");
        CustomerDAO.getInstance().save(customer);

        // Create a service facility
        ServiceFacility sf = ServiceFacilityDAO.getInstance().create(GUID.generate());
        ServiceFacilityDAO.getInstance().save(sf);

        // Create a physical car
        PhysicalCar pc = PhysicalCarDAO.getInstance().create(GUID.generate());
        pc.setVin("SERVICELINEVIN");
        pc.setPrice(25000);
        pc.setColor("Orange");
        PhysicalCarDAO.getInstance().save(pc);

        // Set Service Attributes
        service.setTotalPrice(3000);
        service.setTax(304.23);
        service.setServiceFacilityId(sf.getId());
        service.setTechnicianId(technician.getId());
        service.setCustomerId(customer.getId());
        service.setPhysicalCarId(pc.getId());
        service.setDate(new java.util.Date(2009, 3, 14));
        service.save(); // will save with insert statement

        // Create a task
        String guidt = GUID.generate();
        Task task = TaskDAO.getInstance().create(guidt);
        TaskDAO.getInstance().save(task);

        // Create the Service Line
        ServiceLine serviceLine = ServiceLineDAO.getInstance().create(service.getId(), task.getId());
        serviceLine.setCostOfLabor(1000);
        serviceLine.setCostOfParts(1500);
        serviceLine.save();

        // Test the asserts
        serviceLine.setCostOfLabor(1300);
        serviceLine.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        ServiceLine serviceLine2 = ServiceLineDAO.getInstance().read(service.getId(), task.getId());
        assertSame(serviceLine, serviceLine2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        ServiceLine serviceLine3 = ServiceLineDAO.getInstance().read(service.getId(), task.getId());
        assertNotSame(service, serviceLine3);
        assertEquals(serviceLine.getCostOfLabor(), serviceLine3.getCostOfLabor());
        assertNotNull(serviceLine.getCostOfLabor());
        assertEquals(serviceLine.getCostOfParts(), serviceLine3.getCostOfParts());
        assertNotNull(serviceLine.getCostOfParts());
        assertEquals(serviceLine.getServiceId(), serviceLine3.getServiceId());
        assertNotNull(serviceLine.getServiceId());
        assertEquals(serviceLine.getTaskId(), serviceLine3.getTaskId());
        assertNotNull(serviceLine.getTaskId());

        // Test Part Service Line -- too much stuff to recreate a service line

        // Create the Part
        Part part = PartDAO.getInstance().create(GUID.generate());
        part.save();

        // Create the PSF
        PartsAtServiceFacility psf = PartsAtServiceFacilityDAO.getInstance().create(sf, part);
        psf.save();

        // Create the PSL
        PartServiceLine psl = PartServiceLineDAO.getInstance().create(serviceLine, part.getId());
        psl.setQuantityUsed(5);
        psl.save(); // insert

        psl.setQuantityUsed(3);
        psl.save();

        // Read from cache and make sure they are the same object
        PartServiceLine psl2 = PartServiceLineDAO.getInstance().read(service.getId(), task.getId(), part.getId());
        assertSame(psl, psl2);

        // Clear cache and read from DB
        Cache.getInstance().clear();
        PartServiceLine psl3 = PartServiceLineDAO.getInstance().read(service.getId(), task.getId(), part.getId());
        assertNotSame(psl, psl3);
        assertEquals(psl.getQuantityUsed(), psl3.getQuantityUsed());
        assertNotNull(psl.getQuantityUsed());
    } // testServiceLine

    // Tests the PartsAtServiceFacility BO and DAO */
    public void testPartsAtServiceFacility() throws Exception {
        /////////////////////////////////
        // Create Manufacturers

        // Create Manufacturer1
        Manufacturer man1 = ManufacturerDAO.getInstance().create(GUID.generate());
        man1.setName("Michelin Tire Manufacturer");
        man1.setEmail("satara@gmail.com");
        man1.save();

        // Create Manufacturer2
        Manufacturer man2 = ManufacturerDAO.getInstance().create(GUID.generate());
        man2.setName("Chicago Rotars");
        man2.setEmail("satara@gmail.com");
        man2.save();

        /////////////////////////////////////////////////
        // Create all our parts that need to be reordered

        // Part 1 - Tire
        Part part1 = PartDAO.getInstance().create(GUID.generate());
        part1.setName("Tire");
        part1.setPartNumber("tire0105");
        part1.setManufacturerId(man1.getId());
        part1.save();

        // Part 2 - Snow Tire
        Part part2 = PartDAO.getInstance().create(GUID.generate());
        part2.setName("Snow Tire");
        part2.setPartNumber("snowtire5");
        part2.setManufacturerId(man1.getId());
        part2.save();

        // Part 3 - Rotar
        Part part3 = PartDAO.getInstance().create(GUID.generate());
        part3.setName("Rotar");
        part3.setPartNumber("rotar29348");
        part3.setManufacturerId(man2.getId());
        part3.save();

        // Part 4 - Rotar Deluxe
        Part part4 = PartDAO.getInstance().create(GUID.generate());
        part4.setName("Rotar Deluxe");
        part4.setPartNumber("rotarDeluxe15");
        part4.setManufacturerId(man2.getId());
        part4.save();

        ///////////////////////////////////
        // Create Service Facilities

        // Create Service Facility1 - Tire SF
        ServiceFacility sf1 = ServiceFacilityDAO.getInstance().create(GUID.generate());
        sf1.setAddress("456 Tire Way");
        sf1.save();

        // Create Service Facility2 - Rotars SF
        ServiceFacility sf2 = ServiceFacilityDAO.getInstance().create(GUID.generate());
        sf2.setAddress("789 Rotar Way");
        sf2.save();

        ///////////////////////////////////
        // Create Parts At Service Facilities

        // Create PSF1
        PartsAtServiceFacility psf1 = PartsAtServiceFacilityDAO.getInstance().create(sf1, part1);
        psf1.setQuantity(10);
        psf1.setReorderLevel(50);
        psf1.setQuantityOnOrder(30);
        psf1.setRepurchaseQuantity(20);
        psf1.save(); // insert

        psf1.setQuantity(15);
        psf1.save(); // update

        // Read From Cache
        PartsAtServiceFacility psf2 = PartsAtServiceFacilityDAO.getInstance().read(sf1.getId(), part1.getId());
        assertSame(psf1, psf2);

        // Clear Cache and Read from DB
        Cache.getInstance().clear();
        PartsAtServiceFacility psf3 = PartsAtServiceFacilityDAO.getInstance().read(sf1.getId(), part1.getId());
        assertNotSame(psf1, psf3);

        // Assert Fields
        assertEquals(psf1.getQuantity(), psf3.getQuantity());
        assertNotNull(psf1.getQuantity());
        assertEquals(psf1.getReorderLevel(), psf3.getReorderLevel());
        assertNotNull(psf1.getReorderLevel());
        assertEquals(psf1.getRepurchaseQuantity(), psf3.getRepurchaseQuantity());
        assertNotNull(psf1.getRepurchaseQuantity());
        assertEquals(psf1.getQuantityOnOrder(), psf3.getQuantityOnOrder());
        assertNotNull(psf1.getQuantityOnOrder());

        /////////////////////////////////////////////
        // Create 3 Remaining PSFs for batch process

        // Create PSF4
        PartsAtServiceFacility psf4 = PartsAtServiceFacilityDAO.getInstance().create(sf1, part2);
        psf4.setQuantity(30);
        psf4.setReorderLevel(100);
        psf4.setQuantityOnOrder(50);
        psf4.setRepurchaseQuantity(50);
        psf4.save(); // insert

        // Create PSF5
        PartsAtServiceFacility psf5 = PartsAtServiceFacilityDAO.getInstance().create(sf2, part3);
        psf5.setQuantity(2);
        psf5.setReorderLevel(5);
        psf5.setQuantityOnOrder(2);
        psf5.setRepurchaseQuantity(2);
        psf5.save(); // insert

        // Create PSF6
        PartsAtServiceFacility psf6 = PartsAtServiceFacilityDAO.getInstance().create(sf2, part4);
        psf5.setQuantity(6);
        psf5.setReorderLevel(10);
        psf5.setQuantityOnOrder(4);
        psf5.setRepurchaseQuantity(2);
        psf5.save(); // insert
    }

    /** Tests the Order BO and DAO (this really should be split into many methods) */
    public void testOrder() throws Exception {
        // Create the Order
        String guid = GUID.generate();
        Order order = OrderDAO.getInstance().create(guid);

        // Create a manufacturer
        Manufacturer manufacturer = ManufacturerDAO.getInstance().create(GUID.generate());
        ManufacturerDAO.getInstance().save(manufacturer);

        // Create a service facility
        ServiceFacility sf = ServiceFacilityDAO.getInstance().create(GUID.generate());
        ServiceFacilityDAO.getInstance().save(sf);

        // Set Order Attributes
        order.setServiceFacilityId(sf.getId());
        order.setManufacturerId(manufacturer.getId());
        order.setDate(new java.util.Date(2009, 3, 13));
        order.save(); // will save with insert statement

        order.setDate(new java.util.Date(2009, 3, 14));
        order.save(); // this will save with the update statement

        // this one will come from the cache -- should be the exact same object
        Order order2 = OrderDAO.getInstance().read(guid);
        assertSame(order, order2);

        // this one will come all the way from the DB -- should be a new object
        Cache.getInstance().clear();
        Order order3 = OrderDAO.getInstance().read(guid);
        assertNotSame(order, order3);
        assertEquals(order.getServiceFacilityId(), order3.getServiceFacilityId());
        assertNotNull(order.getServiceFacilityId());
        assertEquals(order.getManufacturerId(), order3.getManufacturerId());
        assertNotNull(order.getManufacturerId());
        assertEquals(order.getDate(), order3.getDate());
        assertNotNull(order.getDate());
    }//testOrder

    /** Tests the orderLine BO and DAO */
    public void testOrderLine() throws Exception {
        // Create a manufacturer
        Manufacturer manufacturer = ManufacturerDAO.getInstance().create(GUID.generate());
        ManufacturerDAO.getInstance().save(manufacturer);

        // Create a service facility
        ServiceFacility sf = ServiceFacilityDAO.getInstance().create(GUID.generate());
        ServiceFacilityDAO.getInstance().save(sf);

        // Create the Order
        String guido = GUID.generate();
        Order order = OrderDAO.getInstance().create(guido);
        order.setManufacturerId(manufacturer.getId());
        order.setServiceFacilityId(sf.getId());
        order.setDate(new java.util.Date(2009, 3, 13));
        order.save();

        // Create a part
        Part part = PartDAO.getInstance().create(GUID.generate());
        part.save();

        // Create the PSF
        PartsAtServiceFacility psf = PartsAtServiceFacilityDAO.getInstance().create(sf, part);
        psf.setQuantity(2000);
        psf.setReorderLevel(100);
        psf.setQuantityOnOrder(50);
        psf.setRepurchaseQuantity(50);
        psf.save();

        // Create the OrderLine
        OrderLine ol = OrderLineDAO.getInstance().create(order, part);
        ol.setQuantity(30);
        ol.save(); // insert

        // Check update
        ol.setQuantity(25);
        ol.save(); // update

        // Check cache
        OrderLine ol2 = OrderLineDAO.getInstance().read(order.getId(), part.getId());
        assertSame(ol, ol2);

        // Check read from database
        Cache.getInstance().clear();
        OrderLine ol3 = OrderLineDAO.getInstance().read(order.getId(), part.getId());
        assertNotSame(ol, ol3);

        // Assert Variables
        assertEquals(ol.getQuantity(), ol3.getQuantity());
        assertNotNull(ol.getQuantity());
        assertEquals(ol.getPartId(), ol3.getPartId());
        assertNotNull(ol.getQuantity());
        assertEquals(ol.getOrderId(), ol3.getOrderId());
        assertNotNull(ol.getOrderId());
    }

    /** Test Order with OrderLines */
    public void testOrderWithOrderLines() throws Exception {
        ///////////////////////////////
        // Create the Order
        String guid = GUID.generate();
        Order order = OrderDAO.getInstance().create(guid);

        // Create a manufacturer
        Manufacturer manufacturer = ManufacturerDAO.getInstance().create(GUID.generate());
        manufacturer.save();

        // Create a service facility
        ServiceFacility sf = ServiceFacilityDAO.getInstance().create(GUID.generate());
        sf.save();

        // Set Order Attributes
        order.setServiceFacilityId(sf.getId());
        order.setManufacturerId(manufacturer.getId());
        order.setDate(new java.util.Date(2009, 3, 13));

        ////////////////////////////////
        // Create the OrderLines

        // Create a part
        Part part = PartDAO.getInstance().create(GUID.generate());
        part.save();

        // Create the PSF
        PartsAtServiceFacility psf = PartsAtServiceFacilityDAO.getInstance().create(sf, part);
        psf.setQuantity(2000);
        psf.setReorderLevel(100);
        psf.setQuantityOnOrder(50);
        psf.setRepurchaseQuantity(50);
        psf.save();

        // Create the OrderLine
        OrderLine ol = OrderLineDAO.getInstance().create(order, part);
        ol.setQuantity(30);

        // Add OrderLine to Order
        order.addOrderLine(ol);

        // Save the order which will call saveNoCommit on the OrderLine
        order.save(); // this will save with the update statement

    }

    /** Test Service with ServiceLines */
    public void testServiceWithServiceLines() throws Exception {
         // Create the Service
        String guids = GUID.generate();
        Service service = ServiceDAO.getInstance().create(guids);

        // Create a technician
        Technician technician = TechnicianDAO.getInstance().create(GUID.generate());
        TechnicianDAO.getInstance().save(technician);

        // Create a customer
        Customer customer = CustomerDAO.getInstance().create(GUID.generate());
        customer.setFirstName("Kellie");
        customer.setLastName("Goff");
        customer.setAddress("720 North Provo UT");
        customer.setPhone("8018610903");
        CustomerDAO.getInstance().save(customer);

        // Create a service facility
        ServiceFacility sf = ServiceFacilityDAO.getInstance().create(GUID.generate());
        ServiceFacilityDAO.getInstance().save(sf);

        // Create a physical car
        PhysicalCar pc = PhysicalCarDAO.getInstance().create(GUID.generate());
        pc.setVin("SERVICELINEVIN2");
        pc.setPrice(30000);
        pc.setColor("Magenta");
        PhysicalCarDAO.getInstance().save(pc);

        // Set Service Attributes
        service.setTotalPrice(2000);
        service.setTax(326.23);
        service.setServiceFacilityId(sf.getId());
        service.setTechnicianId(technician.getId());
        service.setCustomerId(customer.getId());
        service.setPhysicalCarId(pc.getId());
        service.setDate(new java.util.Date(2009, 3, 14));

        // Create a task
        String guidt = GUID.generate();
        Task task = TaskDAO.getInstance().create(guidt);
        TaskDAO.getInstance().save(task);

        // Create the Service Line
        ServiceLine serviceLine = ServiceLineDAO.getInstance().create(service.getId(), task.getId());
        serviceLine.setCostOfLabor(2000);
        serviceLine.setCostOfParts(2500);

        // Add the service line to the Service
        service.addServiceLine(serviceLine);

        ///////////////////////////////
        // Test Part Service Line

        // Create the Part
        Part part = PartDAO.getInstance().create(GUID.generate());
        part.save();

        // Create the PSF
        PartsAtServiceFacility psf = PartsAtServiceFacilityDAO.getInstance().create(sf, part);
        psf.setQuantity(2000);
        psf.setReorderLevel(100);
        psf.setQuantityOnOrder(50);
        psf.setRepurchaseQuantity(50);
        psf.save();

        // Create the PSL
        PartServiceLine psl = PartServiceLineDAO.getInstance().create(serviceLine, part.getId());
        psl.setQuantityUsed(5);

        // Add the PSl to the ServiceLine
        serviceLine.addPslToList(psl);

        // Save the Service which will save the ServiceLine which will save the PSL
        service.save();
    }
}